//
//  TwentyTableViewCell.m
//  QuickReadComic
//
//  Created by 苗钧豪 on 16/9/1.
//  Copyright © 2016年 苗钧豪. All rights reserved.
//

#import "TwentyTableViewCell.h"
#import "TwentyCollectionViewCell.h"
#import "ZWYNetTool.h"
#import "UIImageView+WebCache.h"
@implementation TwentyTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self NetworkRequests];
    _lastPosition = 0;
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    [layout setItemSize:CGSizeMake((self.bounds.size.width), 85)];
    [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 0);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    [self.twentyCollectionView setCollectionViewLayout:layout];
    [_twentyCollectionView registerNib:[UINib nibWithNibName:@"TwentyCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"twenty"];
    _twentyCollectionView.backgroundColor = [UIColor clearColor];
//    _twentyCollectionView.pagingEnabled = YES;
    _twentyCollectionView.delegate = self;
    _twentyCollectionView.dataSource = self;
    _twentyCollectionView.contentSize = CGSizeMake(self.bounds.size.width * 7, 0);
    }
- (void)NetworkRequests {
    [ZWYNetTool GET:@"http://api.kuaikanmanhua.com/v1/topic_new/discovery_list?" andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
        NSLog(@"=====================成功啦");
        self.model = [dataModel modelWithDic:result[@"data"]];
        [self.twentyCollectionView reloadData];
    } andFailureBlock:^(NSError *error) {
        NSLog(@"=====================出错啦");
    }];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 20;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TwentyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"twenty" forIndexPath:indexPath];
    TopicsModel *topics = self.model.infos[self.Number].topics[indexPath.row];
    NSLog(@"\n\n\n%@",self.model.infos);
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",topics.pic]]];
    cell.bookLabel.text = topics.title;
    cell.writerLabel.text = topics.user.nickname;
    cell.numLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row + 1];
    return cell;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
